package com.usian.user.controller.v1;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.usian.common.dtos.ResponseResult;
import com.usian.common.enums.AppHttpCodeEnum;
import com.usian.common.exception.LeadException;
import com.usian.common.util.BeanHelper;
import com.usian.model.user.dtos.UserInfoDto;
import com.usian.model.user.dtos.UserRelationDto;
import com.usian.user.entity.ApUser;
import com.usian.user.entity.ApUserFollow;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.user.service.IApUserService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * APP用户信息表 前端控制器
 * </p>
 *
 * @author usian
 * @since 2022-07-05
 */
@RestController
@RequestMapping("/api/v1/user")
@Api(tags = "APP用户信息表接口")
@CrossOrigin
public class ApUserController{

    @Autowired
    private IApUserService apUserService;


//    关注或取消
    @PostMapping("/user_follow")
    public ResponseResult follow (@RequestBody UserRelationDto dto){
        apUserService.follow(dto);
        return ResponseResult.ok();
    }


    /**
     * 根据用户id和关注作者的id查询
     * @param userId
     * @param followId
     * @return
     */
    @GetMapping("/isUserFollow")
    public Boolean findByUserIdAndFollowId(@RequestParam(name = "userId") Integer userId,
                                           @RequestParam(name = "followId") Integer followId) {
        ApUserFollow apUserFollow = apUserService.findByUserIdAndFollowId(userId, followId);
        if(apUserFollow != null){
            return true;
        }else {
            return false;
        }
    }

//根据id查询用户
    @GetMapping("/{id}")
    public UserInfoDto findById(@PathVariable("id") Integer userId){
        ApUser apUser = apUserService.getById(userId);
        return BeanHelper.copyProperties(apUser, UserInfoDto.class);

    }
}
